<html>
<head>
<title>SQL</title>
</head>
<body bgcolor=white>
<?php
$statement = $_POST["statement"];
if($statement) {
  print "<FORM METHOD =\"POST\" ACTION = \"query.php\">";
  print "<TEXTAREA NAME=\"statement\" ROWS=5 COLS=50>";
  print "</TEXTAREA>";
  print "<input type=\"submit\" value=\"Submit\" />";
  print "</FORM>";
  $link = mysql_connect("localhost", "cs143", "") or die("Connection error");
  mysql_select_db("CS143") or die("DB selection error");
  $query = $statement;
  $result = mysql_query($query) or die("Query error");
  print "<table>\n";
  while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    print "\t<tr>\n";
    foreach ($line as $col_value) {
      print "\t\t<td>$col_value</td>\n";
    }
    print "\t</tr>\n";
  }
  print "</table>\n";
  mysql_free_result($result);
  mysql_close($link);
}
else
{
  print "<FORM METHOD =\"POST\" ACTION = \"query.php\">";
  print "<TEXTAREA NAME=\"statement\" ROWS=5 COLS=40>";
  print "</TEXTAREA>";
  print "<input type=\"submit\" value=\"Submit\" />";
  print "</FORM>";
}
?>
</body>
</html>